{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Auxiliary Mesh Data Structure"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We discuss ways to extract the combinatorial structure of a triangulation by using `elem` array only. Auxiliary data structure includes: \n",
    "- 2D: `edge, elem2edge, edge2elem, neighbor, bdEdge`\n",
    "- 3D: `face, elem2face, face2elem, neighbor, bdFace`\n",
    "\n",
    "They are wrapped into a mesh structure `T` and generated by\n",
    "```\n",
    "    T = auxstructure(elem);  % 2-D\n",
    "    T = auxstructure3(elem); % 3-D\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The auxiliary data structure can be constructed by *sparse matrixlization* efficiently; see [Auxiliary Mesh Data Structure](auxstructuredoc.pdf) for detailed explanation. In the following, we present two examples."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## edge\n",
    "We first complete the 2-D simplicial complex represented by `elem` by constructing 1-dimensional simplices, i.e., edges of the triangulation. We use `edge(1:NE,1:2)` to store indices of the starting and ending points of edges. The column is sorted in a way such that for the k-th edge, `edge(k,1)<edge(k,2)`. The following code will generate an `edge` matrix. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGkCAIAAACgjIjwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nB3RJTUUH4gkHFRQu7wrx4AAAACR0RVh0U29mdHdhcmUATUFUTEFCLCBUaGUgTWF0aFdvcmtzLCBJ\nbmMuPFjdGAAAACJ0RVh0Q3JlYXRpb24gVGltZQAwNy1TZXAtMjAxOCAxNDoyMDo0NufgpwsAACAA\nSURBVHic7d1/eFx1nejxz7TlRylNDwxUEhh6+NG0GNChAbyJYib7+Ah6G+xdMeB1NZNFi+h6lxph\n/YUJ+3h9HpcNqOteoXvtTr2uhcCFaHO1spacgEwoNiWUltJA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ywAuI4goXDhcHj+WcFVq39RzJY0YPe1\nx27kXI0fsQDgLoKEohS5JbEZ+R0LAC4iSChWwVsSm5EaWABwC0GCC7K3pEAOX9qWTA2uf2LN6s7b\n2YzUwAKAK3jZN1xjWVZzc7Nt20GjvNKsXmRelv0FbsnU4IC96fXUYJe10rll165dXMRWCQsARSJI\ncJNt27Zt9/T0WJZlWZaIOHtTMjXkvO3RNM1oNFpXV8ffxUpiAaAYBAlTxbZty7Kcr95w/hDmU5y1\nwgJAvggSAMAT+KQGAIAnECQAgCcQJACAJxAkAIAnECQAgCcQJACAJxAkAIAnECQAgCcQJACAJxAk\nAIAnECQAgCcQJACAJxAkAIAnECQAgCcQJACAJxAkAIAnECQAgCcQJACAJxAkAIAnECQAgCcQJACA\nJxAkAIAnECQAgCcQJACAJxAkAIAnECQAgCcQJACAJxAkAIAnECQAgCf8f+AVijuGsxoOAAAAAElF\nTkSuQmCC\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "[node,elem] = squaremesh([0 1 0 1],0.5);\n",
    "totalEdge = sort([elem(:,[2,3]); elem(:,[3,1]); elem(:,[1,2])],2);\n",
    "[i,j,s] = find(sparse(totalEdge(:,2),totalEdge(:,1),1));\n",
    "edge = [j,i]; \n",
    "bdEdge = [j(s==1),i(s==1)];\n",
    "showmesh(node,elem);\n",
    "findedge(node,edge,s==1);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first line collects all edges from the set of triangles and sorts the column such that `totalEdge(k,1)<totalEdge(k,2)`. The interior edges are repeated twice in `totalEdge`. We use the summation property of `sparse` command to merge the duplicated indices. The nonzero vector `s` takes value 1 (for boundary edges) or 2 (for interior edges). We then use `find` to return the nonzero indices which forms the `edge` set. We can also find the boundary edges using the subset of indices pair corresponding to the nonzero value 1. Note that we switch the order of `(i,j)` in line 3 to sort the edge set row-wise since the output of `find(sparse)` is sorted column-wise. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To construct `edge` matrix only, the above 3 line code can be further simplified to one line:\n",
    "`edge = unique(sort([elem(:,[2,3]); elem(:,[3,1]); elem(:,[1,2])],2),'rows');`\n",
    "The `unique` function provides more functionality which we shall explore more later. However, numerical tests show that the running time of `unique` is around 3 times of the combination `find(sparse)`. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Node Star\n",
    "\n",
    "The `elem` matrix, by the definition, is a link from triangles to vertices, i.e., `elem` is `elem2node`. The link from vertices to triangles, namely given a vertex, to find all triangles containing this vertex, is stored in the sparse matrix:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     1     0     0     1     1     0     0     0     0\n",
      "     0     1     0     0     1     1     0     0     0\n",
      "     0     0     0     1     0     0     1     1     0\n",
      "     0     0     0     0     1     0     0     1     1\n",
      "     1     1     0     0     1     0     0     0     0\n",
      "     0     1     1     0     0     1     0     0     0\n",
      "     0     0     0     1     1     0     0     1     0\n",
      "     0     0     0     0     1     1     0     0     1\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGkCAIAAACgjIjwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nB3RJTUUH4gkHFRcnvfsahwAAACR0RVh0U29mdHdhcmUATUFUTEFCLCBUaGUgTWF0aFdvcmtzLCBJ\nbmMuPFjdGAAAACJ0RVh0Q3JlYXRpb24gVGltZQAwNy1TZXAtMjAxOCAxNDoyMzozOSqrg7MAAB0v\nSURBVHic7d1/jBxl4cfxz9IC4UehQIDYAjeV2j80MRJBoUB3F2qwEH6J0YiNu2fif8QQCCGKSfcM\nICGgBeUfRbsXv/qHwSI/LCLgzVbh+GW1IBGBpgMIEYhtoYUa+uO+f8xwd93bvZv9Nc/zzPN+pX9c\n926mj8fjvHdnnt0pTExMC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BIAAArECQAgBUIEgDACgQJAGAFggQAsAJB\nAgBYgSABAKxAkAAAViBIAAArECQAgBUIEgDACgQJAGAFggQAsAJBAgBYgSABAKxAkAAAViBIAAAr\nECQAgBUIEgDACgQJAGAFggQAsAJBAgBYgSABAKxAkAAAViBIAAArECQAgBUIEgDACgQJAGAFggQA\nsML/A8LpHitCO+rRAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "NT = size(elem,1); N = size(node,1);\n",
    "t2v = sparse([1:NT,1:NT,1:NT], elem, 1, NT, N);\n",
    "display(full(t2v));\n",
    "nodeStar = find(t2v(:,5));\n",
    "showmesh(node,elem);\n",
    "findelem(node,elem,nodeStar);\n",
    "findnode(node,5);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The NT x N matrix `t2v` is the incidence matrix between triangles and vertices. `t2v(t,i)=1` means the i-th node is a vertex of triangle t. If we look at `t2v` column-wise, the nonzero in the i-th column of `t2v(:,i)` will give all triangles containing the $i$-th node. Since sparse matrix is stored column-wise, the star of the $i$-th node can be efficiently found by `nodeStar = find(t2v(:,i))`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## elem2edge\n",
    "\n",
    "We label three edges of a triangle such that the i-th edge is opposite to the i-th vertex. We define the matrix `elem2edge` as the map of local index of edges in each triangle to its global index. The following 3 line code will construct `elem2edge` using more output from `unique` function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "[node,elem] = squaremesh([0 1 0 1],0.5);\n",
    "totalEdge = sort([elem(:,[2,3]); elem(:,[3,1]); elem(:,[1,2])],2);\n",
    "[edge, i2, j] = unique(totalEdge,'rows','legacy');\n",
    "NT = size(elem,1);\n",
    "elem2edge = reshape(j,NT,3);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Line 1 collects all edges element-wise. The size of `totalEdge` is thus 3NT x 2. By the construction, there is a natural index mapping from `totalEdge` to `elem`. In line 2, we apply `unique` function to obtain the edge matrix. The output index vectors `i2` and `j` contain the index mapping between `edge` and `totalEdge`. Here `i2` is a NE x 1 vector to index the last (2-nd in our case) occurrence of each unique value in `totalEdge` such that `edge = totalEdge(i2,:)`, while `j` is a 3NT x 1 vector such that `totalEdge = edge(j,:)`. (Try `help unique` in MATLAB to learn more examples. `legacy` is used since the version change of MATLAB.) Then using the natural index mapping from `totalEdge` to `elem`, we reshape the 3NT x 1 vector `j` to a NT x 3 matrix which is `elem2edge`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "elem2edge =\n",
      "\n",
      "     3     2     8\n",
      "     6     5    11\n",
      "    10     9    15\n",
      "    13    12    16\n",
      "     3     5     1\n",
      "     6     7     4\n",
      "    10    12     8\n",
      "    13    14    11\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGkCAIAAACgjIjwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nB3RJTUUH4gkHFSMVzga48AAAACR0RVh0U29mdHdhcmUATUFUTEFCLCBUaGUgTWF0aFdvcmtzLCBJ\nbmMuPFjdGAAAACJ0RVh0Q3JlYXRpb24gVGltZQAwNy1TZXAtMjAxOCAxNDozNToyMSVgTKwAABu+\nSURBVHic7d17cFzVfcDx35p3HMyCeETGxpcE5LQmRMYJGalJdjVhGsLYGadJXZhkqtWkMU2YTKFO\n6CNJte60mem05t1JcQdYdRogToaaWqXUnVh3myABsYxCbQhKjI8QlRJAYe0mJTzi7R9XyELWrlZ3\n7+499/y+n7/k1d3LmTODvnPuPbs3VS6XBQCAuC2JewAAAIgQJACAJQgSAMAKBAkAYAWCBACwAkEC\nAFiBIAEArECQAABWIEgAACsQJACAFQgSAMAKBAkAYAW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jeAMgpRs1Eg5agSXEKQEo0bKUSM4hiAlFTVSjhrB\nPQQpkaiRctQITiJIyUONlKNGcBVBShhqpBw1gsMIUpJQI+WoEdxGkBKDGilHjeA8gpQM1Eg5agQN\nCFICUCPlqBGUIEi2o0bKUSPoQZCsRo2Uo0ZQhSDZixopR42gDUGyFDVSjhpBIYJkI2qkHDWCTgTJ\nOtRIOWoEtQiSXaiRctQImhEki1Aj5agRlCNItqBGylEjgCBZgRopR40AIUg2oEbKUSMgQJBiRo2U\no0bADIIUJ2qkHDUCZiNIsaFGylEjYA6CFA9qpBw1Ao5HkGJAjZSjRsC8CFKzUSPlqBFQCUFqKmqk\nHDUCqiBIzUONlKNGQHUEqUmokXLUCFgQQWoGaqQcNQJqkSqXy3GPwXGpVEpEsls64h4I4mEGnzdD\n417HSq9zRdxjQTz8bUP8pa0FQWo43/eLxWLcowAQm0wmk81m4x5FAhAkAIAVuIcEALACQQIAWIEg\nAQCsQJAAAFYgSAAAKxAkAIAVCBIAwAoECQBgBYIEALACQQIAWIEgAQCsQJAAAFYgSAAAKxAkAIAV\nCBIAwAoECQBgBYIEALACQQIAWIEgAQCsQJAAAFYgSAAAKxAkAIAVCBIAwAoECQBgBYIEALACQQIA\nWIEgAQCsQJAAAFYgSAAAKxAkAIAVCBIAwAoECQBgBYIEALACQQIAWIEgAQCsQJAAAFYgSAAAKxAk\nAIAVCBIAwAoECQBgBYIEALACQQIAWIEgAQCsQJAAAFb4f2Csdm8Og8C9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "showmesh(node,elem);\n",
    "findelem(node,elem,6);\n",
    "findedge(node,edge,elem2edge(6,:));\n",
    "display(elem2edge);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## edge2elem\n",
    "\n",
    "We then define a NE x 4 matrix `edge2elem` such that `edge2elem(k,1)` and `edge2elem(k,2)` are two triangles sharing the k-th edge for an interior edge. If the k-th edge is on the boundary, then we set `edge2elem(k,1) = edge2elem(k,2)`. Furthermore, we shall record the local indices in `edge2elem(k,3:4)` such that `elem2edge(edge2elem(k,1),edge2elem(k,3))=k`. Similarly `edge2elem(k,4)` is the local index of k-th edge in `edge2elem(k,2)`. \n",
    "\n",
    "To construct `edge2elem` matrix, we need to find out the index map from `edge` to `elem`. The following code is a continuation of the code constructing `elem2edge`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "i1(j(3*NT:-1:1)) = 3*NT:-1:1; i1=i1';\n",
    "k1 = ceil(i1/NT); t1 = i1 - NT*(k1-1);\n",
    "k2 = ceil(i2/NT); t2 = i2 - NT*(k2-1);\n",
    "edge2elem = [t1,t2,k1,k2];"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The code in line 1 uses `j` to find the first occurrence of each unique edge in the `totalEdge`. In MATLAB, when assign values using an index vector with duplication, the value at the repeated index will be the last one assigned to this location. Obvious `j` contains duplication of edge indices. For example, `j(1)=j(2)=4` which means `totalEdge(1,:)=totalEdge(2,:)=edge(4,:)`. We reverse the order of `j` such that `i1(4)=1` which is the first occurrence.\n",
    "\n",
    "Using the natural index mapping from `totalEdge` to `elem`, for an index `i` between `1:N`, the formula `k=ceil(i/NT)` computes the local index of i-th edge, and `t=i-NT*(k-1)` is the global index of the triangle which `totalEdge(i,:)` belongs to. The `edge2elem` is just composed by `t1,t2,k1` and `k2`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "edge2elem =\n",
      "\n",
      "     5     5     3     3\n",
      "     1     1     2     2\n",
      "     1     5     1     1\n",
      "     6     6     3     3\n",
      "     2     5     2     2\n",
      "     2     6     1     1\n",
      "     6     6     2     2\n",
      "     1     7     3     3\n",
      "     3     3     2     2\n",
      "     3     7     1     1\n",
      "     2     8     3     3\n",
      "     4     7     2     2\n",
      "     4     8     1     1\n",
      "     8     8     2     2\n",
      "     3     3     3     3\n",
      "     4     4     3     3\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGkCAIAAACgjIjwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA\nB3RJTUUH4gkHFSAN9kdzZQAAACR0RVh0U29mdHdhcmUATUFUTEFCLCBUaGUgTWF0aFdvcmtzLCBJ\nbmMuPFjdGAAAACJ0RVh0Q3JlYXRpb24gVGltZQAwNy1TZXAtMjAxOCAxNDozMjoxM32URvoAABg/\nSURBVHic7d1vjF3nXeDx3zjOn5Jta+KEYifFVyVxd5WlOASKbHWZOzRSSXBQoi4RoSvNHbFKtG3R\npsq2AvWFxy+2ywu6JaEINdrFM7sFdouEwtoKKNV67iARp6VOTdsEapT6mKR2ITW1G0LbNOnw4kzH\nk/H8vXPvPc85z+cjv7ge33P8OFLuV885z7nPyNzcXABA1bZUPQAAiBAkABIhSAAkQZAASIIgAZAE\nQQIgCYIEQBIECYAkCBIASRAkAJIgSAAkQZAASIIgAZAEQQIgCYIEQBIECYAkCBIASRAkAJIgSAAk\nQZAASIIgAZAEQQIgCYIEQBIECYAkCBIASRAkAJIgSAAkQZAASIIgAZCErVUPoPm63e7s7GzVowAq\nMzo62m63qx5FDYzMzc1VPYaGGxkZmZysehBUpChiaipae9/c2ndD1WOhGt2PHosIn7TrIUgDNzIy\n4r9xnooixsai1Yq4dW/7wX1VD4cKPPrAn0XEiU897ZN2PdxDgoEoa3ToULhUk62yRnf91s9VPZDa\nECToPzVCjXogSNBnaoQa9UaQoJ/UCDXqmSBB36gRarQZggT9oUao0SYJEvSBGqFGmydIsFlqhBr1\nhSDBpqgRatQvggS9UyPUqI8ECXqkRqhRfwkS9EKNUKO+EyTYMDVCjQZBkGBj1Ag1GhBBgg1QI9Ro\ncAQJ1kuNUKOBEiRYFzVC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ABIgiABkARBAiAJggRAEgQJgCQIEgBJECQAkiBI\nACRBkABIgiABkARBAiAJggRAEgQJgCQIEgBJECQAkiBIACRBkABIgiABkARBAiAJggRAEgQJgCQI\nEgBJECQAkiBIACRBkABIgiABkARBAiAJggRAEgQJgCQIEgBJECQAkiBIACRBkABIwr8AkKBtcWvH\nrbwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "showmesh(node,elem);\n",
    "findelem(node,elem,edge2elem(6,1:2));\n",
    "findedge(node,edge,6);\n",
    "display(edge2elem);"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MATLAB",
   "language": "matlab",
   "name": "imatlab"
  },
  "language_info": {
   "codemirror_mode": "octave",
   "file_extension": ".m",
   "mimetype": "text/x-matlab",
   "name": "matlab",
   "pygments_lexer": "matlab",
   "version": "9.9.0.1524771 (R2020b) Update 2"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "30px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": false,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": true,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
